//@author A0087191Y
package net.mysoc.w111j.service.actions;

import net.mysoc.w111j.model.Category;
import net.mysoc.w111j.model.User;

/**
 * An {@code Action} to undo the adding of a {@code Category}.
 */
public class AddCategoryAction implements Action {
    private final User user;
    private final int newCategoryId;
    private String status;

    public AddCategoryAction(User user, Category newCategory) {
        this.user = user;
        this.newCategoryId = newCategory.getId();
        setStatus(newCategory);
    }

    @Override
    public void undo() {
        // The category should have no expenses prior to undoing,
        // therefore it is safe to just delete the category.
        user.removeCategory(newCategoryId);
    }

    @Override
    public String getStatus() {
        return status;
    }

    private void setStatus(Category category) {
        status = "New category added: " + category.getName() + ".";
    }
}
